package com.whut.report;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.whut.common.ReportCommonFunc;
import com.whut.model.*;
import com.whut.parMapper.ParProblemCollectDetailMapper;
import com.whut.parMapper.ParProblemDescriptionMapper;
import com.whut.parMapper.ParSystemMapper;
import com.whut.parMapper.utils.MapperUtils;
import com.whut.service.impl.CheckInfoServiceImpl;
import com.whut.service.impl.ReportServiceImpl;
import com.whut.utils.FileUtil;
import com.whut.utils.MDoc;
import com.whut.utils.pointsCalculate;
import com.whut.v_model.ProblemCollectDetail;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.lang3.StringUtils;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.xml.transform.Source;
import java.awt.*;
import java.io.File;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.whut.service.impl.CheckInfoServiceImpl.IMG_PATH;
import static com.whut.service.impl.CheckInfoServiceImpl.TEST_IMG_PATH;

public class CheckReport {
    @Resource
    private UrlProperties urlProperties;
    @Resource
    private Profiles profiles;
    @Resource
    private ParSystemMapper parSystemMapper;
    @Resource
    private ParProblemDescriptionMapper parProblemDescriptionMapper;
    @Resource
    private ParProblemCollectDetailMapper parProblemCollectDetailMapper;
    @Resource
    private CheckInfoServiceImpl checkInfoServiceImpl;
   // @Resource
    @Autowired
    private ReportServiceImpl reportServiceImpl;


    private MapperUtils mapperUtils;

    private int checkId;
    private int projectId;
    private boolean isNew;
    public static final int WIDTH = 718;
    public static final int HEIGHT = 468;
    public CheckReport(ParSystemMapper parSystemMapper,
                       ParProblemDescriptionMapper parProblemDescriptionMapper,
                       ParProblemCollectDetailMapper parProblemCollectDetailMapper,
                       CheckInfoServiceImpl checkInfoServiceImpl,
                       ReportServiceImpl reportServiceImpl,
                       MapperUtils mapperUtils,
                       UrlProperties urlProperties,
                       Profiles profiles
    ) {
        this.parSystemMapper = parSystemMapper;
        this.parProblemDescriptionMapper = parProblemDescriptionMapper;
        this.parProblemCollectDetailMapper = parProblemCollectDetailMapper;
        this.checkInfoServiceImpl = checkInfoServiceImpl;
        this.reportServiceImpl = reportServiceImpl;
        this.mapperUtils=mapperUtils;
        this.urlProperties=urlProperties;
        this.urlProperties=urlProperties;
        this.profiles=profiles;

    }
    
    
    public String  generateCheckReport(int projectId, int checkId, int reportType,boolean isNew) throws Exception {
        StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
        //设置标题字体
        standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
        //设置图例的字体
        standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
        //设置轴向的字体
        standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
        //应用主题样式
        DecimalFormat df = new DecimalFormat("0.00");
        int width = 718;
        int height = 468;
        ChartFactory.setChartTheme(standardChartTheme);
        Map<String, Object> dataMap = new HashMap<String, Object>();
        Date date = new Date();
        DateFormat d1 = new SimpleDateFormat("yyyyMMddhhmmss");
        DateFormat d2 = new SimpleDateFormat("yyyy");
        DateFormat d3 = new SimpleDateFormat("MM");
        DateFormat d4 = new SimpleDateFormat("dd");
        String day = d4.format(date);
        String month = d3.format(date);
        String year = d2.format(date);
        String fileName = d1.format(date);
        String zlWeight =isNew? parSystemMapper.getWeight1ByName1("新质量检查"):parSystemMapper.getWeight1ByName1("质量检查");
        String aqWeight =isNew?  parSystemMapper.getWeight1ByName1("新安全检查"):parSystemMapper.getWeight1ByName1("安全检查");
        String glWeight =isNew?  parSystemMapper.getWeight1ByName1("新管理行为"):parSystemMapper.getWeight1ByName1("管理行为");
        dataMap.put("zlWeight", zlWeight);
        dataMap.put("aqWeight", aqWeight);
        dataMap.put("glWeight", glWeight);
        dataMap.put("day", day);
        dataMap.put("year", year);
        dataMap.put("month", month);
        dataMap.put("tttt", "1111");

        dataMap.put("zlPoint", "\\");
        dataMap.put("glPoint", "\\");
        dataMap.put("aqPoint", "\\");
        dataMap.put("zlLever", "\\");
        dataMap.put("aqLever", "\\");
        dataMap.put("glLever", "\\");
        DefaultPieDataset datasetPie = new DefaultPieDataset();
        DefaultCategoryDataset datasetBar = new DefaultCategoryDataset();
        final String Bar = "各检查分项";
        //工程概况部分，来自ctp的工程信息
        System.out.println("----"+projectId+dataMap.toString());

        reportServiceImpl.initProjectSummaryFirstPart(projectId,dataMap);
        //工程概况部分，来自设备信息表的设备信息部分
        java.util.List<Equipinfo> equipinfoList = mapperUtils.getEquipinfoMapper().getAllByProjectId(projectId);
        String equip = JSON.toJSONString(equipinfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray equipArray = JSONArray.parseArray(equip);
        java.util.List<Object> equipList = new ArrayList<Object>();
        if (equipArray.size() == 0) {
            Map<String, Object> eqMap = new HashMap<String, Object>();
            eqMap.put("equipType", "\\");
            eqMap.put("equipQua", "\\");
            eqMap.put("equipNum", "\\");
            eqMap.put("equipLeaseUnit", "\\");
            eqMap.put("equipUseUnit", "\\");
            eqMap.put("demolitionUnit", "\\");
            eqMap.put("testUnit", "\\");
            equipList.add(eqMap);
        } else {
            for (int i = 0; i < equipArray.size(); i++) {
                Map<String, Object> eqMap = new HashMap<String, Object>();
                JSONObject equipObject = equipArray.getJSONObject(i);
                eqMap.put("equipType", equipObject.getString("equipType"));
                eqMap.put("equipQua", equipObject.getString("equipQua"));
                eqMap.put("equipNum", equipObject.getString("equipNum"));
                eqMap.put("equipLeaseUnit", equipObject.getString("equipLeaseUnit"));
                eqMap.put("equipUseUnit", equipObject.getString("equipUseUnit"));
                eqMap.put("demolitionUnit", equipObject.getString("demolitionUnit"));
                eqMap.put("testUnit", equipObject.getString("testUnit"));
                equipList.add(eqMap);
            }
        }
        dataMap.put("equipList", equipList);
        //第一部分，综合评估结果，从合同任务检查表中获取相关信息,签名部分
        java.util.List<ContractCheckTask> checkInfo = mapperUtils.getContractchecktaskMapper().getCheckInfoByCheckId(checkId);
        String check = JSON.toJSONString(checkInfo, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray checkArray = JSONArray.parseArray(check);
        JSONObject checkObject = checkArray.getJSONObject(0);

//        dataMap.put("jsSign", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png"));
//        dataMap.put("jlSign", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png"));
//        dataMap.put("sgSign", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png"));
//        dataMap.put("jsSign", MDoc.getImageStr("C:\\Users\\96500\\Desktop\\20190329183836002.png"));
//        dataMap.put("jlSign", MDoc.getImageStr("C:\\Users\\96500\\Desktop\\20190329183836002.png"));
//        dataMap.put("sgSign", MDoc.getImageStr("C:\\Users\\96500\\Desktop\\20190329183836002.png"));
        String signPicPath = checkObject.getString("signPath");
        String jsSign = checkObject.getString("jsSign");
        String jlSign = checkObject.getString("jlSign");
        String sgSign = checkObject.getString("sgSign");

        String imgFile =IMG_PATH+"blank.png";
        String imgFileStr;
        if(!MDoc.isFoundImageStr(imgFile)){
            imgFile=TEST_IMG_PATH;
        }
        if ( (signPicPath==null || signPicPath.equals(""))) {
            imgFileStr=MDoc.getImageStr(imgFile);
            dataMap.put("jsSign", imgFileStr);
            dataMap.put("jlSign", imgFileStr);
            dataMap.put("sgSign", imgFileStr);
        } else {
            dataMap.put("jsSign", MDoc.getImageStr(signPicPath + jsSign));
            dataMap.put("jlSign", MDoc.getImageStr(signPicPath + jlSign));
            dataMap.put("sgSign", MDoc.getImageStr(signPicPath + sgSign));
        }




        //第一部分，（二）分项评估结果
        java.util.List<Integer> pName1Info = parProblemCollectDetailMapper.getAllName1Id(checkId);
        String name1 = JSON.toJSONString(pName1Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray name1Array = JSONArray.parseArray(name1);   //firstId
        float allExtraPointFloat = parProblemCollectDetailMapper.getAllExtraPoint(checkId);
        double allExtraPoint = Double.valueOf(String.valueOf(allExtraPointFloat));
        double overAllPoint = 0;
        Integer taskId = mapperUtils.getContractchecktaskMapper().getTaskIdByCheckId(checkId);
        java.util.List<Object> part2List = new ArrayList<Object>();
        String Name1 = "";
        double allweight1 = 0;
        for (int i = 0; i < name1Array.size(); i++) {
            double Tweight1 = 0;
            String weight1 = parSystemMapper.getWeight1ByName1(parSystemMapper.getName4ByName4Id(name1Array.getIntValue(i)));
            Tweight1 = pointsCalculate.getPercentInstance(weight1);
            allweight1 += Tweight1;
        }
        for (int k = 0; k < name1Array.size(); k++) {
            Map<String, Object> part2Map = new HashMap<String, Object>();
            java.util.List<Object> part2InnerList = new ArrayList<Object>();
            String pName1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(k)); //通过firstId找到pName1
            double Tweight1 = 0;
            String weight1 = parSystemMapper.getWeight1ByName1(pName1);  //获取权重
            Tweight1 = pointsCalculate.getPercentInstance(weight1);
            if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                java.util.List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                String aqLever=" ";
                switch(Integer.parseInt(pointsCalculate.getMaxRiskPoint(list))){
                    case 4:
                        aqLever="一级隐患";
                        break;
                    case 3:
                        aqLever="二级隐患";
                        break;
                    case 2:
                        aqLever="三级隐患";
                        break;
                    case 1:
                        aqLever="四级隐患";
                        break;
                }
                dataMap.put("aqLever", aqLever);
                Name1 = "安全文明";
            } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                java.util.List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                String zlLever=" ";
                switch(Integer.parseInt(pointsCalculate.getMaxRiskPoint(list))){
                    case 4:
                        zlLever="一级隐患";
                        break;
                    case 3:
                        zlLever="二级隐患";
                        break;
                    case 2:
                        zlLever="三级隐患";
                        break;
                    case 1:
                        zlLever="四级隐患";
                        break;
                }
                dataMap.put("zlLever", zlLever);
                Name1 = "质量隐患";
            } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                java.util.List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                String glLever=" ";
                switch(Integer.parseInt(pointsCalculate.getMaxRiskPoint(list))){
                    case 4:
                        glLever="一级隐患";
                        break;
                    case 3:
                        glLever="二级隐患";
                        break;
                    case 2:
                        glLever="三级隐患";
                        break;
                    case 1:
                        glLever="四级隐患";
                        break;
                }
                dataMap.put("glLever", glLever);
                Name1 = "管理行为";
            }
            part2Map.put("name1No", k + 1);
            part2Map.put("name1", Name1);
            java.util.List<Object> secondIdList = parProblemCollectDetailMapper.getSecondId(checkId, pName1);  //获取secondIdList
            String secondIdInfo = JSON.toJSONString(secondIdList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray secondIdInfoArray = JSONArray.parseArray(secondIdInfo);
            double allweight2 = 0;
            for (int p = 0; p < secondIdInfoArray.size(); p++) {
                int allsecondId = secondIdInfoArray.getIntValue(p);
                String weight2 = parSystemMapper.getWeight3ByThirdId(allsecondId);
                double weight22 = pointsCalculate.getPercentInstance(weight2);
                allweight2 += weight22;
            }
            double allsecondPoint = 0;
            for (int u = 0; u < secondIdInfoArray.size(); u++) {
                int secondId = secondIdInfoArray.getIntValue(u);
                double weight222 = 0;
                String weight2 = parSystemMapper.getWeight3ByThirdId(secondId); //获取第三级权重的weight
                weight222 = pointsCalculate.getPercentInstance(weight2);
                double point = 0;

                java.util.List<ProblemCollectDetail> fourthPoints = parProblemCollectDetailMapper.getFourthPoint(checkId, pName1, secondId);
                String fourthCalculateInfo = JSON.toJSONString(fourthPoints, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray fourthPointsCalculateArray = JSONArray.parseArray(fourthCalculateInfo);
                //添加无问题项
                List<ProblemCollectDetail> noProblemItemList = new ArrayList<>();
                List<Noproblemitem> noProblemFourthId= mapperUtils.getNoproblemitemMapper().getFourthIdList(checkId,secondId);
                for (Noproblemitem noproblemitem : noProblemFourthId){
                    ProblemCollectDetail pcd = new ProblemCollectDetail();
                    pcd.setFourthId(noproblemitem.getFourthId());
                    pcd.setThirdId(noproblemitem.getThirdId());
                    String weight3= parSystemMapper.getWeight3ByThirdId(noproblemitem.getThirdId());
                    String weight4= parSystemMapper.getWeight3ByThirdId(noproblemitem.getFourthId());
                    pcd.setWeight3(weight3);
                    pcd.setWeight4(weight4);
                    String pName4 = parSystemMapper.getName4ByName4Id(noproblemitem.getFourthId());
                    pcd.setpName4(pName4);
                    pcd.setPoint3(parSystemMapper.getPoint4ByPoint4Id(noproblemitem.getThirdId()));
                    pcd.setPoint4(parSystemMapper.getPoint4ByPoint4Id(noproblemitem.getFourthId()));
                    noProblemItemList.add(pcd);
                }
//                List<ProblemCollectDetail> noProblemItemList = parProblemCollectDetailMapper.getNoProblemItem(checkId, secondId);
                String noProblemCalculateInfo = JSON.toJSONString(noProblemItemList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray noProblemCalculateArray = JSONArray.parseArray(noProblemCalculateInfo);
                for (int j = 0; j < noProblemCalculateArray.size(); j++) {
                    Map<String, Object> part2InnerMap = new HashMap<String, Object>();
                    JSONObject part2InnerObject = noProblemCalculateArray.getJSONObject(j);
                    Double point4=Double.parseDouble(part2InnerObject.getString("point4"));
                    point += point4*pointsCalculate.getPercentInstance(part2InnerObject.getString("weight3"));
                    part2InnerMap.put("pName4", noProblemItemList.get(j).getpName4());
                    part2InnerMap.put("weight4",part2InnerObject.getString("weight3"));
                    part2InnerMap.put("checkItemPoint", part2InnerObject.getString("point4"));
                    part2InnerList.add(part2InnerMap);
                }
                for (int j = 0; j < fourthPointsCalculateArray.size(); j++) {
                    Map<String, Object> part2InnerMap = new HashMap<String, Object>();
                    JSONObject part2InnerObject = fourthPointsCalculateArray.getJSONObject(j);
                    part2InnerMap.put("pName4", part2InnerObject.getString("pName4"));

                    double allweight4 = reportServiceImpl.calculateAllWeight4Func(checkId, part2InnerObject,taskId , isNew);
                    double weight3 = 0;
                    double weight4 = 0;
                    int part2FourthId = part2InnerObject.getIntValue("fourthId");
                    int part2ThirdId = part2InnerObject.getIntValue("thirdId");
//                    weight3 = pointsCalculate.getPercentInstance(part2InnerObject.getString("weight3"));
//                    weight4 = pointsCalculate.getPercentInstance(part2InnerObject.getString("weight4"));
                    String newWeight4 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(part2FourthId,taskId);
                    if(StringUtils.isNotBlank(newWeight4)){
                        weight4 = pointsCalculate.getPercentInstance(newWeight4);
                    }else {
                        weight4 = pointsCalculate.getPercentInstance(part2InnerObject.getString("weight4"));
                    }
                    String newWeight3 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(part2ThirdId,taskId);
                    if(StringUtils.isNotBlank(newWeight3)){
                        weight3 = pointsCalculate.getPercentInstance(newWeight3);
                    }else {
                        weight3 = pointsCalculate.getPercentInstance(part2InnerObject.getString("weight3"));
                    }

                    String weight4Result = reportServiceImpl.getPart2InnerListweight4(checkId, part2ThirdId, weight3, weight4, allweight4,isNew);
                    part2InnerMap.put("weight4", weight4Result);

                    java.util.List<ProblemCollectDetail> sixthPoints = parProblemCollectDetailMapper.getsixthPoints(checkId, part2FourthId);
                    String pointName6Info = JSON.toJSONString(sixthPoints, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                    JSONArray sixthPointsArray = JSONArray.parseArray(pointName6Info);
                    double calculatePoint6 = 0;
                    double calculateTruePoint = 0;
                    java.util.List<Double> calculatePointList = reportServiceImpl.calculatePoint6Func(sixthPointsArray, checkId,isNew);
                    calculatePoint6 = calculatePointList.get(1);
                    calculateTruePoint = calculatePointList.get(0);
                    double noProblemPoint = reportServiceImpl.calculateNoProblemPointFunc(checkId, part2InnerObject,isNew);
                    System.out.println("第六级扣过的分数总分:" + calculatePoint6 + "没有问题的总分:" + noProblemPoint + "第六级总分:" + calculateTruePoint);
                    double checkItemPoint = (calculatePoint6 + noProblemPoint) / (calculateTruePoint + noProblemPoint) * 100;
                    String s = reportServiceImpl.getCheckItemPointAndUpdateAllPointSave(checkId, part2FourthId, projectId, checkItemPoint, df,isNew);

                    part2InnerMap.put("checkItemPoint", s);
                    //point += checkItemPoint * weight3 / countFourthId;
                    point += checkItemPoint * weight3 / (allweight4/weight4);
                    //System.out.println("这里可能有问题："+point+" "+j+" " +checkItemPoint+" "+weight3+ " "+allweight4+" "+weight4);
                    part2InnerList.add(part2InnerMap);
                }

                java.util.List<Object> getThirdId = parProblemCollectDetailMapper.getThirdId(checkId, pName1, secondId);
                String thirdIdInfo = JSON.toJSONString(getThirdId, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray thirdArray = JSONArray.parseArray(thirdIdInfo);
                /*thirdArray中还需要加入无问题项的内容*/
                List<Object> noProblemThirdId= mapperUtils.getNoproblemitemMapper().getThirdIdList(checkId,secondId);
                for (Object obj : noProblemThirdId){
                    thirdArray.add(obj);
                }
                double allweight3 = 0;
                for (int v = 0; v < thirdArray.size(); v++) {
                    double Tweight3 = 0;
                    int thirdId = thirdArray.getIntValue(v);

//                    String trueweight3 = parSystemMapper.getWeight3ByThirdId(thirdId);
//                    Tweight3 = pointsCalculate.getPercentInstance(trueweight3);

                    String newWeight3 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(thirdId, taskId);
                    if (StringUtils.isNotBlank(newWeight3)){
                        Tweight3 = pointsCalculate.getPercentInstance(newWeight3);
                    }else{
                        String trueweight3 = parSystemMapper.getWeight3ByThirdId(thirdId);
                        Tweight3 = pointsCalculate.getPercentInstance(trueweight3);
                    }

                    allweight3 += Tweight3;
                }
                System.out.println(point+"dasdasdadasd"+allweight3+"dasdsadsadad"+df.format(point / allweight3));
                double thirdPoint = Double.parseDouble(df.format(point / allweight3));
                double percent2 = Double.parseDouble(df.format(weight222 / allweight2));
                double secondPoint = Double.parseDouble(df.format(thirdPoint * percent2));
                allsecondPoint += secondPoint;
            }

            if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                dataMap.put("aqPoint", allsecondPoint);
            } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                dataMap.put("zlPoint", allsecondPoint);
            } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                dataMap.put("glPoint", allsecondPoint);
            }
            int firstPointCount = mapperUtils.getAllpointsaveMapper().getAllPointCountByCheckId(checkId, name1Array.getInteger(k));
            if (firstPointCount != 0) {
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date1 = new Date(System.currentTimeMillis());
                String lastEditTime=formatter.format(date1);
                mapperUtils.getAllpointsaveMapper().updateAllPoint(checkId, df.format(allsecondPoint), name1Array.getInteger(k),lastEditTime);
            } else {
                Allpointsave allpointsave = new Allpointsave();
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date1 = new Date(System.currentTimeMillis());
                allpointsave.setNewCreateTime(formatter.format(date1));
                allpointsave.setLastEditTime(formatter.format(date1));
                allpointsave.setCheckId(checkId);
                allpointsave.setNumber(name1Array.getInteger(k));
                allpointsave.setPoint(df.format(allsecondPoint));
                allpointsave.setProjectId(projectId);
                mapperUtils.getAllpointsaveMapper().insert(allpointsave);
            }
            double trueWeight1 = Double.parseDouble(df.format(Tweight1 / allweight1));
            overAllPoint += Double.parseDouble(df.format(trueWeight1 * allsecondPoint));
            part2Map.put("point", allsecondPoint);
            part2Map.put("part2InnerList", part2InnerList);
            part2List.add(part2Map);
        }
        overAllPoint = overAllPoint - allExtraPoint;
        dataMap.put("overAllPoint", overAllPoint);
        //将总分存到ALLPOINTSAVE中
        int allPointInDB = mapperUtils.getAllpointsaveMapper().getAllPointCountByCheckId(checkId, -1);
        if (allPointInDB != 0) {
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date1 = new Date(System.currentTimeMillis());
            String lastEditTime=formatter.format(date1);
            mapperUtils.getAllpointsaveMapper().updateAllPoint(checkId, df.format(overAllPoint), -1,lastEditTime);
        } else {
            Allpointsave allpointsave = new Allpointsave();
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
            Date date1 = new Date(System.currentTimeMillis());
            allpointsave.setNewCreateTime(formatter.format(date1));
            allpointsave.setLastEditTime(formatter.format(date1));
            allpointsave.setCheckId(checkId);
            allpointsave.setNumber(-1);
            allpointsave.setProjectId(projectId);
            allpointsave.setPoint(df.format(overAllPoint));
            mapperUtils.getAllpointsaveMapper().insert(allpointsave);
        }
        //将总分存到CCT表中
        ContractCheckTask contractchecktask = new ContractCheckTask();
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date1 = new Date(System.currentTimeMillis());
        contractchecktask.setLastEditTime(formatter.format(date1));
        contractchecktask.setCheckId(checkId);
        contractchecktask.setTotalPoint(String.valueOf(overAllPoint));
        mapperUtils.getContractchecktaskMapper().updateByPrimaryKeySelective(contractchecktask);

        java.util.List<ProblemCollectDetail> overallList = parProblemCollectDetailMapper.getAllProblemCollectInfoByCheckId(checkId);
        String overAllLever=" ";
        switch(Integer.parseInt(pointsCalculate.getMaxRiskPoint(overallList))){
            case 4:
                overAllLever="一级隐患";
                break;
            case 3:
                overAllLever="二级隐患";
                break;
            case 2:
                overAllLever="三级隐患";
                break;
            case 1:
                overAllLever="四级隐患";
                break;
        }
        dataMap.put("overAllLever", overAllLever);
        ContractTaskProject contractTaskProjectRiskPoint = new ContractTaskProject();
        contractTaskProjectRiskPoint.setProjectId(projectId);
        contractTaskProjectRiskPoint.setLatestRiskLevel(pointsCalculate.getMaxRiskPoint(overallList));
        contractTaskProjectRiskPoint.setLastEditTime(formatter.format(date1));
        mapperUtils.getContractTaskProjectMapper().updateByPrimaryKeySelective(contractTaskProjectRiskPoint);
        ContractTaskProject newRiskList = mapperUtils.getContractTaskProjectMapper().selectByPrimaryKey(projectId);
        String finishTime = mapperUtils.getContractchecktaskMapper().getFinishTimeByCheckId(checkId);
        if (newRiskList.getCheckTime().equals("") || newRiskList.getCheckTime().compareTo(finishTime) <= 0) {
            try {
                ContractTaskProject contracttaskproject = new ContractTaskProject();
                contracttaskproject.setProjectId(projectId);
                contracttaskproject.setLatestCheckTime(finishTime);
                contracttaskproject.setLastEditTime(formatter.format(date1));
                mapperUtils.getContractTaskProjectMapper().updateByPrimaryKeySelective(contracttaskproject);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        dataMap.put("part2List", part2List);

        //第一部分，（三）各个专业问题的分布情况
        java.util.List<Integer> pName4Info = parProblemCollectDetailMapper.getAllName4(checkId);
        int allProblemNum = parProblemCollectDetailMapper.getAllNum(checkId);
        dataMap.put("allProblemNum", allProblemNum);
        String name4 = JSON.toJSONString(pName4Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray name4Array = JSONArray.parseArray(name4);
        java.util.List<Object> part3List = new ArrayList<Object>();
        for (int m = 0; m < name4Array.size(); m++) {
            Map<String, Object> part3Map = new HashMap<String, Object>();
            int pName4Id = name4Array.getIntValue(m);
            String pName4 = parSystemMapper.getName4ByName4Id(pName4Id);
            int name4Num = parProblemCollectDetailMapper.countName4(pName4Id, checkId);
            String percent = pointsCalculate.caculateToPercent(name4Num, allProblemNum);
            part3Map.put("No", m + 1);
            part3Map.put("name4", pName4);
            part3Map.put("problemNum", name4Num);
            part3Map.put("percent", percent);
            datasetPie.setValue(pName4 + ":" + percent, new Double(name4Num));
            datasetBar.addValue(name4Num, Bar, pName4);
            part3List.add(part3Map);
        }
        dataMap.put("part3List", part3List);

        //第一部分，三.检查问题综述
        if (reportType == 1) {
            java.util.List<Object> part4List = new ArrayList<Object>();
            for (int i = 0; i < name1Array.size(); i++) {
                java.util.List<Object> part4InnerList = new ArrayList<Object>();
                Map<String, Object> part4Map = new HashMap<String, Object>();
                String pName1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(i));
                System.out.println("000000000000000000"+name1Array.getIntValue(i));
                java.util.List<Summary> summaryList = mapperUtils.getSummaryMapper().getSummaryInfo(checkId, name1Array.getIntValue(i));
                String summaryInfo = JSON.toJSONString(summaryList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray summaryInfoArray = JSONArray.parseArray(summaryInfo);
                for (int j = 0; j < summaryInfoArray.size(); j++) {
                    Map<String, Object> part4InnerMap = new HashMap<String, Object>();
                    JSONObject part4InnerObject = summaryInfoArray.getJSONObject(j);
                    String part4pNname4 = parSystemMapper.getName4ByName4Id(part4InnerObject.getIntValue("fourthId"));
                    part4InnerMap.put("pName4", part4pNname4);
                    part4InnerMap.put("summary", part4InnerObject.getString("summary"));
                    part4InnerList.add(part4InnerMap);
                }

                if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                    part4Map.put("name1", "安全");
                } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                    part4Map.put("name1", "新质量");
                } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                    part4Map.put("name1", "管理");
                } else if (pName1.equals("设备检查")||pName1.equals("新设备检查")) {
                    part4Map.put("name1", "检查");
                }
//                part4Map.put("name1", pName1);
                part4Map.put("part4InnerList", part4InnerList);
                part4List.add(part4Map);
            }
            dataMap.put("part4List", part4List);
        } else if (reportType == 2) {
            java.util.List<Object> partProblemList = new ArrayList<Object>();
            for (int i = 0; i < name1Array.size(); i++) {
                java.util.List<Object> partProblemName1List = new ArrayList<Object>();
                Map<String, Object> partProblemMap = new HashMap<String, Object>();
                String pName1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(i));
                java.util.List<Integer> problemName4List = parProblemCollectDetailMapper.getAllName4ByName1(checkId, pName1);
                String problemName4Info = JSON.toJSONString(problemName4List, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray problemName4Array = JSONArray.parseArray(problemName4Info);
                for (int k = 0; k < problemName4Array.size(); k++) {
                    java.util.List<ProblemCollectDetail> partProblemDetailList = parProblemCollectDetailMapper.getAllFourthInfo(checkId, problemName4Array.getIntValue(k));
                    String partProblemDetailInfo = JSON.toJSONString(partProblemDetailList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                    JSONArray partProblemDetailArray = JSONArray.parseArray(partProblemDetailInfo);
                    String problemName4 = parSystemMapper.getName4ByName4Id(problemName4Array.getIntValue(k));
                    for (int j = 0; j < partProblemDetailArray.size(); j++) {
                        Map<String, Object> partProblemName1Map = new HashMap<String, Object>();
                        JSONObject partProblemObject = partProblemDetailArray.getJSONObject(j);
                        String problemDescription = partProblemObject.getString("problemDescription");
                        String riskPoint = partProblemObject.getString("riskPoint");
                        if (partProblemObject.getString("isRemark").equals("N")) {
                            partProblemName1Map.put("problemDescription", problemDescription);
                        } else if (partProblemObject.getString("isRemark").equals("Y")) {
                            partProblemName1Map.put("problemDescription", partProblemObject.getString("remark"));
                        }
                        String riskLevel=" ";
                        if(partProblemObject.getString("riskPoint").length()==1){
                        switch(Integer.parseInt(partProblemObject.getString("riskPoint"))){
                            case 4:
                                riskLevel="一级";
                                break;
                            case 3:
                                riskLevel="二级";
                                break;
                            case 2:
                                riskLevel="三级";
                                break;
                            case 1:
                                riskLevel="四级";
                                break;
                        } }
                        partProblemName1Map.put("riskPoint", riskLevel);
                        partProblemName1Map.put("name4", problemName4);
                        partProblemName1List.add(partProblemName1Map);
                    }
                }
                if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                    partProblemMap.put("name1", "安全");
                } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                    partProblemMap.put("name1", "质量");
                } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                    partProblemMap.put("name1", "管理行为");
                }

                partProblemMap.put("partProblemName1List", partProblemName1List);
                partProblemList.add(partProblemMap);
            }
            dataMap.put("partProblemList", partProblemList);
            int txNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "提醒");
            int oneNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "1");
            int twoNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "2");
            int threeNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "3");
            int fourNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "4");
            dataMap.put("txNum", txNum);
            dataMap.put("oneNum", oneNum);
            dataMap.put("twoNum", twoNum);
            dataMap.put("threeNum", threeNum);
            dataMap.put("fourNum", fourNum);
            String txPercent = pointsCalculate.caculateToPercent(txNum, allProblemNum);
            String onePercent = pointsCalculate.caculateToPercent(oneNum, allProblemNum);
            String twoPercent = pointsCalculate.caculateToPercent(twoNum, allProblemNum);
            String threePercent = pointsCalculate.caculateToPercent(threeNum, allProblemNum);
            String fourPercent = pointsCalculate.caculateToPercent(fourNum, allProblemNum);
            String txAndOnePercent = pointsCalculate.caculateToPercent(txNum + oneNum, allProblemNum);
            dataMap.put("txPercent", txPercent);
            dataMap.put("onePercent", onePercent);
            dataMap.put("twoPercent", twoPercent);
            dataMap.put("threePercent", threePercent);
            dataMap.put("fourPercent", fourPercent);
            DefaultPieDataset datasetRiskPie = new DefaultPieDataset();
            DefaultCategoryDataset datasetRiskBar = new DefaultCategoryDataset();
            datasetRiskPie.setValue("提醒和特征值1" + ":" + txAndOnePercent, new Double(txNum + oneNum));
            datasetRiskPie.setValue("特征值2" + ":" + twoPercent, new Double(twoNum));
            datasetRiskPie.setValue("特征值3" + ":" + threePercent, new Double(threeNum));
            datasetRiskPie.setValue("特征值4" + ":" + fourPercent, new Double(fourNum));
            final String flag1 = "提醒和特征值1";
            final String flag2 = "特征值2";
            final String flag3 = "特征值3";
            final String flag4 = "特征值4";
            final String riskBar = "特征值情况统计";
            datasetRiskBar.addValue(txNum + oneNum, flag1, riskBar);
            datasetRiskBar.addValue(twoNum, flag2, riskBar);
            datasetRiskBar.addValue(threeNum, flag3, riskBar);
            datasetRiskBar.addValue(fourNum, flag4, riskBar);
            try {
                JFreeChart chart = ChartFactory.createPieChart("隐患分布饼图", datasetRiskPie, true, true, false);
                final PiePlot plot = (PiePlot) chart.getPlot();
                plot.setStartAngle(0);
                plot.setForegroundAlpha(0.90f);
                plot.setInteriorGap(0.02);
                chart.getLegend().setVisible(false);
                plot.setSectionPaint("特征值1" + ":" + txAndOnePercent, new Color(49, 95, 232));
                plot.setSectionPaint("特征值2" + ":" + twoPercent, new Color(232, 232, 49));
                plot.setSectionPaint("特征值3" + ":" + threePercent, new Color(240, 117, 60));
                plot.setSectionPaint("特征值4" + ":" + fourPercent, new Color(232, 36, 18));

                File pieChart = new File(IMG_PATH + fileName + "RiskpieChart.png");
                ChartUtils.saveChartAsPNG(pieChart, chart, width, height);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                JFreeChart barChart = ChartFactory.createBarChart("隐患分布直方图",
                        "",
                        "数量",
                        datasetRiskBar,
                        PlotOrientation.VERTICAL,
                        true, true, false);
                CategoryPlot plot = (CategoryPlot) barChart.getPlot();
                plot.getRenderer().setSeriesPaint(0, new Color(49, 95, 232));
                plot.getRenderer().setSeriesPaint(1, new Color(232, 232, 49));
                plot.getRenderer().setSeriesPaint(2, new Color(240, 117, 60));
                plot.getRenderer().setSeriesPaint(3, new Color(232, 36, 18));
                BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
                barRenderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
                barRenderer.setDefaultItemLabelsVisible(true);
                barRenderer.setItemLabelAnchorOffset(-20D);
                //File barChartFile = new File("C:\\Users\\96500\\Desktop\\test\\" + fileName + "RiskbarChart.png");
                File barChartFile = new File(IMG_PATH + fileName + "RiskbarChart.png");
                ChartUtils.saveChartAsPNG(barChartFile, barChart, width, height);

            } catch (Exception e) {
                e.printStackTrace();
            }
            String RiskpieChartImgPath=IMG_PATH + fileName + "RiskpieChart.png";
            String RiskbarChartImgPath=IMG_PATH + fileName + "RiskbarChart.png";
            dataMap.put("pic8", MDoc.getImageStr(RiskpieChartImgPath));
            dataMap.put("pic9", MDoc.getImageStr(RiskbarChartImgPath));


        }


        //第二部分，各部分工程检查情况
        String section2pName1 = "";
        java.util.List<Object> section2List = new ArrayList<Object>();
        for (int b = 0; b < name1Array.size(); b++) {
            Map<String, Object> section2Name1Map = new HashMap<String, Object>();
            java.util.List<Object> section2name1List = new ArrayList<Object>();
            String section2name1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(b));
            if (section2name1.equals("安全检查")||section2name1.equals("新安全检查")) {
                section2pName1 = "安全问题";
            } else if (section2name1.equals("质量检查")||section2name1.equals("新质量检查")) {
                section2pName1 = "质量问题";
            } else if (section2name1.equals("管理行为")||section2name1.equals("新管理行为")) {
                section2pName1 = "管理体系及管理动作";
            }
            section2Name1Map.put("section2pName1", section2pName1);
            java.util.List<Integer> section2Name4Info = parProblemCollectDetailMapper.getAllName4ByName1(checkId, section2name1);
            String section2Name44 = JSON.toJSONString(section2Name4Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray section2Name4Array = JSONArray.parseArray(section2Name44);
            for (int w = 0; w < section2Name4Array.size(); w++) {
                Map<String, Object> section2Name4Map = new HashMap<String, Object>();
                java.util.List<Object> section2Name4List = new ArrayList<Object>();
                int section2Name4Id = section2Name4Array.getIntValue(w);
                String section2Name4 = parSystemMapper.getName4ByName4Id(section2Name4Id);
                java.util.List<ProblemCollectDetail> section2Name6Info = parProblemCollectDetailMapper.getAllName6InfoByName4(checkId, section2Name4Id, section2name1);
                String section2Name66 = JSON.toJSONString(section2Name6Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray section2Name6Array = JSONArray.parseArray(section2Name66);
                for (int c = 0; c < section2Name6Array.size(); c++) {
                    Map<String, Object> section2Name6Map = new HashMap<String, Object>();
                    List<Object> picList = new ArrayList<Object>();
                    JSONObject section2Name6Object = section2Name6Array.getJSONObject(c);
                    section2Name6Map.put("section2pName6No", c + 1);
                    section2Name6Map.put("section2pName6", section2Name6Object.getString("pName6"));
                    section2Name6Map.put("section2pName5", section2Name6Object.getString("pName5"));
                    String riskLevel=" ";
                    if(section2Name6Object.getString("riskPoint").length()==1){
                    switch(Integer.parseInt(section2Name6Object.getString("riskPoint"))){
                        case 4:
                            riskLevel="一级隐患";
                            break;
                        case 3:
                            riskLevel="二级隐患";
                            break;
                        case 2:
                            riskLevel="三级隐患";
                            break;
                        case 1:
                            riskLevel="四级隐患";
                            break;
                    }}
                    section2Name6Map.put("section2RiskLevel", riskLevel);
                    section2Name6Map.put("section2CheckPart", section2Name6Object.getString("checkPart"));
                    section2Name6Map.put("section2ProblemNum", section2Name6Object.getString("problemQua"));
                    if (section2Name6Object.getString("isRemark").equals("N")) {
                        section2Name6Map.put("section2problemDescription", section2Name6Object.getString("problemDescription"));
                    } else if (section2Name6Object.getString("isRemark").equals("Y")) {
                        section2Name6Map.put("section2problemDescription", section2Name6Object.getString("remark"));
                    }
                    section2Name6Map.put("section2normsProvison", section2Name6Object.getString("normsProvison"));
                    section2Name6Map.put("section2suggestion", section2Name6Object.getString("suggestion"));
                    String section2picPath = section2Name6Object.getString("picPath");
                    String picName = section2Name6Object.getString("picName");
                    JSONArray ja = JSONArray.parseArray(picName);
                    if (ja.size() == 0) {
//                        String s = MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\123.png");
                        String imgPath = IMG_PATH+ "noPic.png";
                        if(!MDoc.isFoundImageStr(imgPath)){
                            imgPath=TEST_IMG_PATH;
                        }
                        String s = MDoc.getImageStr(imgPath);
                        picList.add(s);
                    } else {
                        for (int o = 0; o < ja.size(); o++) {
                            String s="";
                            if("prod".equals(profiles.getActives())){
                                s = MDoc.getImageStr(section2picPath + ja.getString(o));
                            }
                            //String s = MDoc.getImageStr(section2picPath + ja.getString(o));
                           //String s = MDoc.getImageStr("D:\\whutServer\\generatedCharts\\test.png");
                            picList.add(s);
                        }
                    }
                    section2Name6Map.put("picList", picList);
                    section2Name4List.add(section2Name6Map);

                }
                section2Name4Map.put("section2pName4", section2Name4);
                section2Name4Map.put("section2Name4List", section2Name4List);
                section2name1List.add(section2Name4Map);
            }
            section2Name1Map.put("section2Name1List", section2name1List);
            section2List.add(section2Name1Map);
        }
        String pieChartImgPath="";
        String barChartImgPath= "";
        try {
            JFreeChart chart = ChartFactory.createPieChart("现场施工问题分布饼图", datasetPie, true, true, false);
            final PiePlot plot = (PiePlot) chart.getPlot();
            plot.setStartAngle(270);
            plot.setForegroundAlpha(0.90f);
            plot.setInteriorGap(0.02);
            chart.getLegend().setVisible(false);
            //File pieChart = new File("C:\\Users\\96500\\Desktop\\test\\" + fileName + "pieChart.png");
            pieChartImgPath =IMG_PATH + fileName + "pieChart.png";
            File pieChart = new File(pieChartImgPath);
//            File pieChart = new File("E:\\tencent_File\\1296928795\\FileRecv\\yirui\\" + fileName + "pieChart.png");
            ChartUtils.saveChartAsPNG(pieChart, chart, width, height);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            JFreeChart barChart = ChartFactory.createBarChart("现场施工问题分布直方图",
                    "",
                    "数量",
                    datasetBar,
                    PlotOrientation.VERTICAL,
                    true, true, false);
            CategoryPlot plot = (CategoryPlot) barChart.getPlot();
            plot.getRenderer().setSeriesPaint(0, new Color(5, 87, 232));
            BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
            barRenderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
            barRenderer.setDefaultItemLabelsVisible(true);
            barRenderer.setItemLabelAnchorOffset(-20D);
            barRenderer.setMaximumBarWidth(0.2);
            CategoryAxis categoryAxis = plot.getDomainAxis();
            categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
            //File barChartFile = new File("C:\\Users\\96500\\Desktop\\test\\" + fileName + "barChart.png");
            barChartImgPath =IMG_PATH + fileName + "barChart.png";
            File barChartFile = new File(barChartImgPath);
//            File barChartFile = new File("E:\\tencent_File\\1296928795\\FileRecv\\yirui\\" + fileName + "barChart.png");

            ChartUtils.saveChartAsPNG(barChartFile, barChart, width, height);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //dataMap.put("pic6", MDoc.getImageStr("C:\\Users\\96500\\Desktop\\test\\" + fileName + "pieChart.png"));
        //dataMap.put("pic7", MDoc.getImageStr("C:\\Users\\96500\\Desktop\\test\\" + fileName + "barChart.png"));

        dataMap.put("pic6", MDoc.getImageStr(pieChartImgPath));
        dataMap.put("pic7", MDoc.getImageStr(barChartImgPath));
//        dataMap.put("pic6", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\yirui\\" + fileName + "pieChart.png"));
//        dataMap.put("pic7", MDoc.getImageStr("E:\\tencent_File\\1296928795\\FileRecv\\yirui\\" + fileName + "barChart.png"));
        dataMap.put("section2List", section2List);
        MDoc mdoc = new MDoc();
      /*  if (reportType == 1) {
            mdoc.createDoc(dataMap, "C:\\Users\\96500\\Desktop\\test\\" + fileName + ".doc", "ftl\\5.0.ftl");
            MDoc.docToDocx("C:\\Users\\96500\\Desktop\\test\\" + fileName + ".doc", "C:\\Users\\96500\\Desktop\\test\\" + fileName + ".doc");
        } else if (reportType == 2) {
            mdoc.createDoc(dataMap, "C:\\Users\\96500\\Desktop\\Risktest\\" + fileName + ".doc", "ftl\\Risk2.0.ftl");
            MDoc.docToDocx("C:\\Users\\96500\\Desktop\\Risktest\\" + fileName + ".doc", "C:\\Users\\96500\\Desktop\\Risktest\\" + fileName + ".doc");
        }
        return "success";*/
        String path = FileUtil.getServerFolderPath();
        System.out.println(path);
        File f1 = new File(path, "doc");
        if (!f1.exists()) {
            f1.mkdirs();
        }
        String result="";
        if (reportType == 1) {

            //生成报告
            DateTimeFormatter dateTime = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
            String fileNameTime = dateTime.format(LocalDateTime.now());
            String reportName = dataMap.get("projectName").toString().replace('#','号')+"小结报告" + fileNameTime;
            String ftlName = "5.0";
            BeanMap beanMap = new BeanMap(dataMap);
            return ReportCommonFunc.generateReport(dataMap, reportName, ftlName);

        } else if (reportType == 2) {
           DateTimeFormatter dateTime = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
            String fileNameTime = dateTime.format(LocalDateTime.now());
            String reportName = dataMap.get("projectName").toString().replace('#','号')+"隐患报告" + fileNameTime;
            String ftlName = "Risk2.0";
            BeanMap beanMap = new BeanMap(dataMap);
            return ReportCommonFunc.generateReport(dataMap, reportName, ftlName);
        }
        return result;
    }
}
